<template>
  <!-- 配件价格检查 -->
  <div>
    <TopFilter :list="inspectionTopFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="waxPriceOfPartsCheckA3v"
      :datakey="'rows'"
      :columns="columns"
      :onColumnsChange="columns => (this.columns = columns)"
      :isSelectColumn="false"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isExportExcel="isExport"
      :onCalcExportData="exportFun"
      exportFileName="配件价格检查.xlsx"
    >
      <!-- :onEnterEvent="doubleClick" -->
      <template slot="controls" slot-scope="props">
        <!-- <AjaxButton size="small" type="primary" icon="el-icon-daochu" :disabled="exportBtn" :click="handleExport">导出</AjaxButton> -->
        <!-- <AjaxButton size="small" type="primary" icon="el-icon-printer" :disabled="printBtn" :click="handlePrint">打印</AjaxButton> -->
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- <AttachDoubleClick :PERIOD="PERIOD" @close="closeHandler" /> -->
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getPriceInjectionList, getExcelList } from '@/api/part/report/priceOfPartsInspection';
import { getAllUser, queryTex } from '@/api/part/common';
import { exportExcelFile } from '@/utils/index';
import moment from 'moment';
export default {
  name: 'PriceOfPartsInspection',
  components: {},
  mixins: [dictionary],
  props: [],
  data() {
    return {
      inspectionTopFilterList: this.createInspectionTopFilterList(),
      columns: this.createTableList(),
      fetchParams: { xhrAbort: true },
      fetchApi: getPriceInjectionList,
      exportBtn: false,
      printBtn: false,
      visible: false,
      dialogTitle: '明细',
      PERIOD: {},
      condition: [],
      queryParam: {},
      isExport: true, // 是否显示导出
      userList: [], // 员工列表
      tax: 0
    };
  },
  created() {
    this.getUsers();
    // this.handleTableSearch();
    this.getTax();
  },
  methods: {
    exportFun(row) {
      if (row.referPrice) {
        row.referPrice = Number(row.referPrice * (1 + Number(this.tax))).toFixed(2);
      }
      for (const key in row) {
        switch (key) {
          // 格式化日期
          case 'operateDate':
            // case 'FINISHED_DATE':
            // case 'BALANCE_TIME':
            // case 'SQUARE_DATE':
            if (row[key]) {
              row[key] = moment(row[key]).format('YYYY-MM-DD');
            }
            break;
          // 格式化人名
          case 'CONSULTANT':
            if (row[key]) {
              // row[key] = this.userList[row[key]];
            }
            break;
          // 格式化金额
          case 'inOutTaxedPrice':
          case 'costPrice':
            if (row[key]) {
              row[key] = Number(row[key]).toFixed(2);
            }
            break;
          default:
            break;
        }
      }
    },
    // 获取数据
    async getTax() {
      let res = await queryTex();
      this.tax = res.data;
    },
    // 获取所有员工
    async getUsers() {
      let res = await getAllUser();
      if (res.resultCode == 200) {
        res.data.map(e => {
          this.userList[e.userId] = e.employeeName;
        });
      }
    },
    // 双击处理
    doubleClick(val) {},
    // 打印处理
    handlePrint() {},
    // 导出处理
    handleExport() {
      const option = {};
      console.log('查询参数', this.fetchParams);
      getExcelList(this.queryParam).then(response => {
        console.log(response, '附件采购额及返利查询');
        exportExcelFile(response.data, '配件价格检查');
        // this.exportLoading = false;
        // this.exportExcel(res.records);
      });
    },
    // 展开收起调用函数(表单重新计算高度)
    collapseHandle() {
      this.$nextTick(() => {
        this.$refs.table.EXECUTE_RESET_HEIGHT();
      });
    },
    // 关闭操作
    closeHandler() {
      this.visible = false;
    },
    // 搜索条件改变调用方法
    async changeHandle(val) {
      this.queryParam = val;
      this.fetchParams = Object.assign({}, { xhrAbort: false }, val);
    },
    // 创建表单字段列表
    createTableList() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },
        // {
        //   title: '网络代码',
        //   dataIndex: 'KUNNR',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '主组号',
          dataIndex: 'mainGroupNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: 'ABC分类',
          dataIndex: 'abcType',
          dictItems: this.createDictList('8092'),
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8092'),
          render: props => {
            return <span>{this.createDictText(props.row.abcType, '8092')}</span>;
          }
        },
        {
          title: '对应单编号',
          dataIndex: 'flowId',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '配件分类代码',
          dataIndex: 'partSortCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          filterItems: this.createDictList('8106'),
          dictItems: this.createDictList('8106'),
          render: props => {
            return <span>{this.createDictText(props.row.partSortCode, '8106')}</span>;
          }
        },
        {
          title: '计量单位',
          dataIndex: 'unitName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '含税出库单价',
          dataIndex: 'inOutTaxedPrice',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '不含税成本单价',
          dataIndex: 'costPrice',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '含税参考零售价',
          dataIndex: 'referPrice',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          render: props => {
            return <span>{Number(props.row.referPrice * (1 + Number(this.tax))).toFixed(2)}</span>;
          }
        },
        {
          title: '出库数量',
          dataIndex: 'stockOutQuantity',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单据编号',
          dataIndex: 'sheetNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '入出方式',
          dataIndex: 'inOutType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8249'),
          dictItems: this.createDictList('8249'),
          render: props => {
            return <span>{this.createDictText(props.row.inOutType, '8249')}</span>;
          }
        },
        {
          title: '常用件标识',
          dataIndex: 'isCommonPart',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isCommonPart, '1004')}</span>;
          }
        },
        {
          title: '车型代码',
          dataIndex: 'modelCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '停用标识',
          dataIndex: 'partStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.partStatus, '1004')}</span>;
          }
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '操作员代码',
          dataIndex: 'operator',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '操作员名称',
          dataIndex: 'operatorName',
          sorter: true,
          filter: true,
          filterType: 'input',
          // filterItems: this.createDictList('1004'),
          // dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.userList[props.row.operator]}</span>;
          }
        },
        {
          title: '出库日期',
          dataIndex: 'operateDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '加价率',
          dataIndex: 'priceAddRate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '参考加价率',
          dataIndex: 'temp',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    // 创建筛选条件
    createInspectionTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '出库日期',
          fieldName: 'dateStart|dateEnd',
          placeholder: '',
          initialValue: [
            moment()
              .startOf('month')
              .format('YYYY-MM-DD'),
            moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
          ],
          rules: [{ required: true, message: '请选择出库日期', trigger: 'blur' }]
        },
        {
          type: 'RADIO',
          label: '',
          fieldName: 'type',
          initialValue: '1',
          itemList: [
            { text: '全部', value: '1' },
            { text: '超限价', value: '2' },
            { text: '低于成本价', value: '3' }
          ],
          placeholder: ''
          // rules: [{ required: true, message: '请选择出库日期', trigger: 'blur' }]
        }
      ];
    }
  }
};
</script>

<style></style>
